<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>product force index</title>
    <script src="./sso.js"></script>
    <script src="./jquery.js"></script>
</head>

<body>
    <h1>产品参谋 DEMO <a href="javascript:;" onclick="logout()">logout</a></h1>
    <p>usrtype:<input id="user-type" value="" style="width: 30%;"/></p>
    <p>apptype:<input id="app-type" value="" style="width: 30%;"/></p>
    <p>restype:<input id="res-type" value="" style="width: 30%;"/></p>
    <p>biltype:<input id="bill-type" value="" style="width: 30%;"/></p>
</body>
<script>
    $(document).ajaxSend(function (event, jqxhr, settings) {
        var auth = getCookie('Authorization');
        if(auth) jqxhr.setRequestHeader('Authorization', auth)
    })

    $(function () {
        getType('user:type');
        // getType('app:type');
        // getType('res:type');
        // getType('bill:type');
    })

    function getType(type) {
        var url='http://pf.com/frontis-user-server/dict/';
        $.ajax({
            url: url + type,
            type: 'GET',
            success: function (res) {
                if(res.code==403){
                    alert("无权限");
                    return;
                }
                var id = type.replace(":", "-");
                $("#" + id).val(JSON.stringify(res.data));
            },
            error: function(){
                toLogin();
            }
        });
    }

    function logout() {
        sessionStorage.setItem("visitUri", window.location.href);
        var token =  getCookie('Authorization');
        if(!token) token = '';
        location.href = "http://pf.com/logout?redirect_uri=http://pf.com/callback.html&access_token="+token;
    }

</script>

</html>